﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Card.Manager.Controls
{
    public partial class UserPicker1 : BasePage
    {
        #region 属性

        public new string NoPermissionUrl = "../NoPermission.aspx?from=";

        public string CIDUserID
        {
            get
            {
                return Request.QueryString["txt"];
            }
        }

        public string CIDSubmitButton
        {
            get
            {
                return Request.QueryString["btn"];
            }
        }

        public bool AutoPostBack
        {
            get
            {
                return string.IsNullOrEmpty(Request.QueryString["a"]) ? false : bool.Parse(Request.QueryString["a"]);
            }
        }

        private string ExcludeUserIDs
        {
            get
            {
                return Request.QueryString["eu"];
            }
        }

        protected int TopNum
        {
            get
            {
                if (Utility.ValidationHelper.IsNumber(this.txtRecords.Text.Trim()))
                {
                    return int.Parse(this.txtRecords.Text.Trim().ToString());
                }
                else
                {
                    this.txtRecords.Text = "50";
                }
                return 50;
            }
        }
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindDepts();
                this.DoInit();
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.DoInit();
        }
        #endregion

        #region 方法
        private void DoInit()
        {
            string strSeach = this.txtSearch.Text.Trim();
            int deptId = 0;
            if (this.dropDept != null && !string.IsNullOrEmpty(this.dropDept.SelectedValue))
            {
                deptId = int.Parse(this.dropDept.SelectedValue);
            }
            string isActive = this.dropIsActive.SelectedValue;
            DataTable dtData = BAF.BLL.SYSUsersManager.GetList(strSeach, deptId, isActive, this.TopNum, Passport);
            DataView dv = dtData.DefaultView;
            if (!string.IsNullOrEmpty(this.ExcludeUserIDs))
            {
                dv.RowFilter = string.Format("USER_ID NOT IN ({0})", ExcludeUserIDs);
            }

            this.rptList.DataSource = dv;
            this.rptList.DataBind();
        }

        /// <summary>
        /// 绑定部门信息
        /// </summary>
        private void BindDepts()
        {
            DataSet ds = BAF.BLL.SYSDepartmentManager.GetList(string.Empty, Passport);
            this.dropDept.DataSource = ds;
            this.dropDept.DataTextField = "DEPT_NAME";
            this.dropDept.DataValueField = "DEPT_ID";
            this.dropDept.DataBind();
            this.dropDept.Items.Insert(0, new ListItem("--请选择--", ""));
        }
        #endregion
    }
}
